package com.yangluyao.test.lockDemo;

import java.util.concurrent.CountDownLatch;

/**
 * @author YLY
 * @ClassName CountDownLatchDemo
 * @Date 2020/5/7
 * @Version 1.0.2
 * CountDownLatch
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        country();
    }

    private static void country() throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <=6 ; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"国\t被灭 ");
                countDownLatch.countDown();
            }, CountryEnum.forEachEnum(i).getRetMessage()).start();
        }

        countDownLatch.await();
        System.out.println("秦国 \t一统天下  ");
    }

    private static void closeDoor() throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <=6 ; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t 号同学离开教室");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"\t 同学走完班长关门");
    }
}
